import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_module/common/base/base_page.dart';
import 'package:flutter_module/common/utils/toast_utils.dart';
import 'package:flutter_module/common/widget/loading_progress.dart';
import 'package:flutter_module/playgroound/play_ground_page.dart';

/// Create by kyluzoi
/// Date: 2021-08-16
///
/// Description: Toast 案例代码

class ToastPage extends BaseStatelessWidget {

  List<ItemVo> items = [
    ItemVo(
        content: "success",
        itemClick: () => ToastUtils().showSuccessText("success")),
    ItemVo(
        content: "info", itemClick: () => ToastUtils().showErrorText("info")),
    ItemVo(
        content: "error", itemClick: () => ToastUtils().showInfoText("error")),
    ItemVo(
        content: "hub",
        itemClick: () {
          // Progress 的 还是不建议使用 Toast
          ToastUtils().showHudText("hub");
          Future.delayed(Duration(milliseconds: 3000), () {
            ToastUtils().dismissHud();
          });
        }),
    ItemVo(
        content: "hub no text",
        itemClick: () {
          ToastUtils().showHud();
          Future.delayed(Duration(milliseconds: 1000), () {
            ToastUtils().dismissHud();
          });
        }),
    ItemVo(
        content: "ProgressDialog 建议使用这个",
        itemClick: () {
          LoadingProgressDialog dialog = LoadingProgressDialog(
            text: "loading",
          );
          dialog.show();
          Future.delayed(Duration(milliseconds: 2000), () {
            dialog.disMiss();
          });
        }),
  ];

  @override
  Widget createView(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: BackButton(
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          title: Text("Toast 案例"),
        ),
        body: _createView());
  }

  _createView() {
    return ListView.builder(
        itemCount: items.length,
        itemBuilder: (context, index) {
          return ItemView(
              item: items[index],
              onPress: items[index].itemClick ??
                  () {
                    throw ("未配置 点击事件");
                  });
        });
  }
}
